<template>
  <div class="btn-dropdown">
    <el-dropdown :popper-options="{ modifiers: [{ name: 'computeStyles', options: { adaptive: false } }] }">
      <div class="el-dropdown-link">
        <el-tag size="large" effect="plain">{{ i18nStore.locale }}</el-tag>
      </div>
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item :style="{ color: i18nStore.locale === item ? 'var(--el-color-primary)' : 'unset' }" v-for="(item, index) in i18nStore.getI18nList" :key="index" @click="languageChange(item)">{{ item }}</el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>

<script setup lang="ts">
import { useI18nStore } from '@/stores/i18n'
const i18nStore = useI18nStore()
// 语言切换
const languageChange = (item: string) => {
  i18nStore.setLocale(item);
}
</script>

<style lang="scss" scoped>
.btn-dropdown {
  .el-dropdown {
    display: flex;
    align-items: center;
    height: 100%;
  }

  .el-dropdown-link {
    height: 100%;
    padding: 8px;
    transition: all 0.2s ease-in-out;
    cursor: pointer;

    .el-tag {
      width: 40px !important;
    }
  }
}

.el-dropdown-link {
  display: flex;
  align-items: center;

  &:focus-visible {
    outline: none;
  }
}
</style>
